package deom8;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2023-04-11
 * Time: 6:45
 */
class ListNode{
    int val;
    ListNode next = null;
    public  ListNode(int val){
        this.val = val;
    }
}
public class Test1 {
    public ListNode removeNthFromEnd(ListNode head,int n){
        ListNode pHead = new ListNode(-1);
        pHead.next = head;
        ListNode fast = pHead;
        ListNode slow = pHead;
        while (n > 0){
            fast = fast.next;
            n-- ;
        }
        while (fast.next != null){
            fast = fast.next;
            slow = slow.next;
        }
        slow.next = slow.next.next;
        return pHead.next;
    }
}
